package com.ruoyi.web.controller.bpmn;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.BpmnModel;
import com.ruoyi.system.service.IBpmnModelService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2020-12-17
 */
@Controller
@RequestMapping("/bpmn/model")
public class BpmnModelController extends BaseController {
    private String prefix = "bpmn/model";

    @Autowired
    private IBpmnModelService bpmnModelService;

    @RequiresPermissions("bpmn:model:view")
    @GetMapping()
    public String model() {
        return prefix + "/model";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("bpmn:model:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BpmnModel bpmnModel) {
        startPage();
        List<BpmnModel> list = bpmnModelService.selectBpmnModelList(bpmnModel);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("bpmn:model:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BpmnModel bpmnModel) {
        List<BpmnModel> list = bpmnModelService.selectBpmnModelList(bpmnModel);
        ExcelUtil<BpmnModel> util = new ExcelUtil<BpmnModel>(BpmnModel.class);
        return util.exportExcel(list, "model");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("bpmn:model:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BpmnModel bpmnModel) {
        bpmnModel.setCreateBy(ShiroUtils.getLoginName());
        bpmnModel.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(bpmnModelService.insertBpmnModel(bpmnModel));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BpmnModel bpmnModel = bpmnModelService.selectBpmnModelById(id);
        mmap.put("bpmnModel", bpmnModel);
        return prefix + "/edit";
    }


    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("bpmn:model:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BpmnModel bpmnModel) {
        return toAjax(bpmnModelService.updateBpmnModel(bpmnModel));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("bpmn:model:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bpmnModelService.deleteBpmnModelByIds(ids));
    }
}
